<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
    <link rel="stylesheet" href="./css/common.css">

    <style>
        .item {
            height: 50px;
            border-bottom: 1px solid #ebebee;
        }
        
        nav {
            height: 50px;
        }
        
        .btn {
            width: 40%;
            height: 40px;
        }
        
        .btn.del {
            background-color: red;
        }
    </style>
</head>

<body>
    <nav class="bg-fff f20 aic flex pl-10">
        <a href="./list.html" style="width: 50px;">返回</a>
        <span class="fcc fg1">爱豆详情</span>
        <span style="width: 50px;"></span>
    </nav>
    <ul class="mt-10" id="box">
        
    </ul>

    <div class="fcc mt-30">
        <button class="btn edit">编辑</button>
        <button class="del btn ml-15">删除</button>
    </div>


    <script src="https://cdn.bootcdn.net/ajax/libs/zepto/1.2.0/zepto.js"></script>
    <script>
        $(()=>{
            var search=location.search
            var id=search.replace(/\?id=(.*)/,"$1")
            $.ajax({
                url:'http://localhost:8880/detail',
                type:'get',
                data:{_id:id},
                dataType:'json',
                success:function(res){
                    if(res.code==666){
                            var str=`
                            <li class="bg-fff item flex jc-sb pl-15 pr-15 aic f16 rel">
                                <span class="f14">头像地址</span>
                                <span class="f14">${res.data.headUrl}</span>
                            </li>
                            <li class="bg-fff item flex jc-sb pl-15 pr-15 aic f16 rel">
                                <span class="f14">姓名</span>
                                <span class="f14">${res.data.name}</span>
                            </li>
                            <li class="bg-fff item flex jc-sb pl-15 pr-15 aic f16 rel">
                                <span class="f14">年龄</span>
                                <span class="f14">${res.data.age}岁</span>
                            </li>
                            <li class="bg-fff item flex jc-sb pl-15 pr-15 aic f16 rel">
                                <span class="f14">职业</span>
                                <span class="f14">${res.data.profession}</span>
                            </li>
                            <li class="bg-fff item flex jc-sb pl-15 pr-15 aic f16 rel">
                                <span class="f14">作品</span>
                                <span class="f14">${res.data.word}</span>
                            </li>
                        `
                        $('#box').html(str)
                    }
                },
                error:function(error){
                    console.log(error)
                }
            })
            $('.edit').click(function(){
                location.href='edit.html?id='+id
            })
            $('.del').click(function(){
                $.ajax({
                    url:'http://localhost:8880/delete',
                    type:'get',
                    data:{
                        _id:id
                    },
                    dataType:'json',
                    success:function(res){
                        if(res.code==666){
                            alert(res.msg)
                            location.href='list.html'
                        }
                    },
                    error:function(error){
                        console.log(error)
                    }
                })
            })
        })
    </script>
</body>

</html>